<?php
// This controller handles the logic for the landing pages

class LandingController extends Controller
{
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	/**
	 * Description: This method renders the supplier landing page if the guest is logged in and is a supplier. If the user is not a supplier
	 * then the user will not be given access to the page. If the viewer is not logged in, then the application will redirect the view
	 * to the login page.
	 * Returns: Nothing
	 */
	public function actionSupplier() 
	{		
		if(Yii::app()->user->isGuest)
		{
			echo "please login first. We will redirect you to the login page in 3 secs";
			header("refresh:3;url=".Yii::app()->request->baseUrl);
		}
		else if(Yii::app()->user->userType=='b')
		{
			echo "you have no authority to view the supplier page";
		}
		else
			$this->render('supplier');
	}

	/**
	 * Description: This method renders the buyer landing page if the guest is logged in and is a buyer. If the user is not a buyer
	 * then the user will not be given access to the page. If the viewer is not logged in, then the application will redirect the view
	 * to the login page.
	 * Returns: Nothing
	 */
	public function actionBuyer() 
	{
		if(Yii::app()->user->isGuest)
		{
			echo "please login first. We will redirect you to the login page in 3 secs";
			header("refresh:3;url=".Yii::app()->request->baseUrl);
		}
		else if(Yii::app()->user->userType=='s')
		{
			echo "you have no authority to view the buyer page";
		}
		else
			$this->render('buyer');
	}
}

?>